<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23具名插槽和作用域</title>
</head>
<body>
<div id="app">
    <!--把父组件的message绑定到子组件的parentMessage，父组件的message值修改后子组件的parentMessage值也会修改-->
    <!--html标签中要用连接符，props声明和使用要遵循camel规则-->
    <!--<inner-button-counter01 v-bind:parent-message="message"></inner-button-counter01>-->
    <!--<inner-button-counter01 v-bind:parent-message="message">!!!</inner-button-counter01>-->
    <!--<inner-button-counter01 v-bind:parent-message="message" v-slot:header>@@@</inner-button-counter01>-->
    <!--自定义组件中插槽传值默认使用父组件的属性-->
    <inner-button-counter01 v-bind:parent-message="message" v-slot:header>插槽传值: {{ message }}</inner-button-counter01>
    <!--使用插槽使用子组件的属性时不能对插槽加name-->
    <!--插槽获取子组件属性值01-->
    <inner-button-counter02 v-bind:parent-message="message" v-slot:default="slotProps">插槽传值: {{ slotProps.abc }}</inner-button-counter02>
</div>
<script src="../vue.global.3.0.5.js"></script>
<script>
    //创建局部组件(推荐)
    const innerButtonCounter01 = {
        data() {
            return {
                message: "子组件message"
            }
        },
        //prop通信
        props: ["parentMessage"],
        template: `
            <div>{{ message }}</div>
            <div>template内部: {{ parentMessage }}</div>
            <!--插槽获取子组件属性值02-->
            <div><slot name="header" v-bind:abc="message">000</slot></div>
        `
    }
    const innerButtonCounter02 = {
        data() {
            return {
                message: "子组件message"
            }
        },
        //prop通信
        props: ["parentMessage"],
        template: `
            <div>{{ message }}</div>
            <div>template内部: {{ parentMessage }}</div>
            <div><slot v-bind:abc="message">000</slot></div>
        `
    }

    //1、创建一个Vue应用实例，本身是最顶层的根组件
    const app = Vue.createApp({
        data() {
            return { message: "父组件message"}
        },
        //定义一个局部组件，本组件是根组件的子组件(推荐)
        components: {
            "inner-button-counter01": innerButtonCounter01,
            "inner-button-counter02": innerButtonCounter02
        }
    });
    //2、定义一个全局组件
    app.component('button-counter', {
        //数据
        data() {
            return {counter: 100}
        },
        //模板
        template: `
            计算器: {{counter}}
            <button v-on:click="counter++">counter++</button><br>
        `
    });
    //3、挂载
    const vm = app.mount("#app");
</script>
</body>
</html>